﻿//
// Created by LiuYou on 2021/4/19.
//

#include <iostream>

template<typename T, typename... Types>
//void printf(const char* s, T& value, Types& ... args);
void printfS(const char* s, T value, Types ... args);

void printfS(const char* s);


int main() {
    int* ptr = nullptr;
    printfS("%d%f%s%p", 100, 4.4, "I love C/C++ forever!", ptr);


    return 0;
}

template<typename T, typename... Types>
void
printfS(const char* s, T value, Types... args) {
    while (*s) {
        if ((*s == '%' && *(++s) != '%')) {
            std::cout << value;
            printfS(++s, args...);
            return;
        }
        std::cout << *s++;
    }
    throw std::logic_error("错误");
}

void printfS(const char* s) {
    while (*s) {
        if (*s == '%' && *(++s) != '%') {
            throw std::runtime_error("错误");
        }
        std::cout << *s++;
    }
}